package gov.pr.celepar.sentinela.dao.postgre;

import gov.pr.celepar.sentinela.Constants;
import gov.pr.celepar.sentinela.dao.ParametrosDAO;
import gov.pr.celepar.sentinela.dao.UsuarioDAO;
import gov.pr.celepar.sentinela.dao.factory.DAOFactory;

import gov.pr.celepar.sentinela.client.SentinelaConfig;
import gov.pr.celepar.sentinela.geral.conexao.Connector;

import java.sql.Connection;
import java.sql.SQLException;

public class PSQLDAOFactory extends DAOFactory {

	public void closeConnection(Connection conn) throws SQLException {
		if (conn != null) {
			conn.close();
		}
	}

	public Connection createConnection() throws Exception {

		SentinelaConfig sentinelaConfig = (SentinelaConfig) SentinelaConfig
				.getInstance();
		String sentinelaDS = sentinelaConfig.getSentinelaDS();
		String datasource = Constants.DS_SENTINELA_CLIENT;

		if (sentinelaDS != null)
			datasource = sentinelaDS;
		Connection conn = Connector.getInstance().getConnection(datasource);
		return conn;
	}

	public ParametrosDAO getParametrosDAO() {
		return new PSQLParametrosDAO();
	}

	public UsuarioDAO getUsuarioDAO() {
		return new PSQLUsuarioDAO();
	}

}
